<?php
function lilina_userapi_getall_stories($args)
{
    extract($args);
    if (!isset($startnum)) {
        $startnum = 1;
    }
    if (!isset($numitems)) {
        $numitems = -1;
    }
    $links = array();
    if(!xarSecurityCheck('OverviewLilina')) return;
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $stable = $xartable['story'];
    $query = "SELECT xar_id,
                     xar_title,
                     xar_summary,
                     xar_link,
                     xar_timestamp,
                     xar_ctitle,
                     xar_curl,
                     xar_cfavicon,
                     xar_unique
            FROM $stable";
    if (!empty($catid) && xarModIsHooked('categories','lilina')) {
        $categoriesdef = xarModAPIFunc('categories','user','leftjoin',
                                       array('cids' => array($catid),
                                            'modid' => xarModGetIDFromName('lilina')));
        if (!empty($categoriesdef)) {
            $query .= ' LEFT JOIN ' . $categoriesdef['table'];
            $query .= ' ON ' . $categoriesdef['field'] . ' = xar_id';
            if (!empty($categoriesdef['more'])) {
                $query .= $categoriesdef['more'];
            }
            if (!empty($categoriesdef['where'])) {
                $query .= ' WHERE ' . $categoriesdef['where'];
            }
        }
    }
    if (isset($timerange)){
        $timesetting = time() - $timerange;
        $query .= " WHERE xar_timestamp > $timesetting";
    }
    $query .= " ORDER BY xar_timestamp DESC";
    $result =& $dbconn->SelectLimit($query, $numitems, $startnum-1);
    if (!$result) return;
    for (; !$result->EOF; $result->MoveNext()) {
        list($id, $title, $summary, $link, $timestamp, $ctitle, $curl, $cfavicon, $unique) = $result->fields;
        if (xarSecurityCheck('OverviewLilina')) {
            $links[] = array('id'       => $id,
                             'title'    => $title,
                             'summary'  => $summary,
                             'link'     => $link,
                             'timestamp'=> $timestamp,
                             'ctitle'   => $ctitle,
                             'curl'     => $curl,
                             'cfavicon' => $cfavicon,
                             'unique'   => $unique);
        }
    }
    $result->Close();
    return $links;
}
?>